package net.protocol;

public class ProtocolFactory {
	
	private static ProtocolFactory instance;
	private Protocol protocol;
	
	public static void register(Protocol protocol){
		if(instance != null)
			throw new RuntimeException("A protocol has already been registred.");
		
		instance = new ProtocolFactory(protocol);
	}
	
	public static ProtocolFactory getInstance(){
		if(instance == null)
			throw new RuntimeException("No protocol has been registred yet.");
		
		return instance;
	}
	
	private ProtocolFactory(Protocol protocol){
		this.protocol = protocol;
	}
	
	public static Protocol getProtocol(){
		return getInstance().protocol.create();
	}
}
